﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Xml.Serialization;

namespace SerialDemo
{
    [XmlRoot("shoppingList")]
    public class ShoppingList
    {
        private ArrayList shoppingItems = new ArrayList();

        public ShoppingList()
        {
        }

        [XmlElement("item")]
        public Item[] Items
        {
            get
            {
                var items = new Item[this.shoppingItems.Count];
                this.shoppingItems.CopyTo(items);
                return items;
            }
            set
            {
                if (value == null)
                {
                    return;
                }
                Item[] items = value;
                this.shoppingItems.Clear();
                foreach (Item item in items)
                {
                    this.shoppingItems.Add(item);
                }
            }
        }

        public int AddItem(Item item)
        {
            return this.shoppingItems.Add(item);
        }

        public void RemoveItem(Item item)
        {
            this.shoppingItems.Remove(item);
        }

    }

    public class Item
    {
        [XmlAttribute("name")]
        public string Name { get; set; }
        [XmlAttribute("price")]
        public double Price { get; set; }

        public Item()
        {
        }

        public Item(string Name, double Price)
        {
            this.Name = Name;
            this.Price = Price;
        }
    }
}